<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>企业logo上传管理</title>
    <style>
        #uploadDiv {
            color: #666666;
            height: 500px;
            width: 400px;
            /*text-align:center;*/
            font-size: 18px;
        }

    </style>
</head>
<body>

<div id="uploadDiv">
    <form id="uploadPic" enctype="multipart/form-data" method="post">
        <input type="file" id="pic">
        <input id="hiddenUrl" type="hidden" value="">
        <input type="button" id="uploadButton" value="上传图片" onclick="uploadPic()">
        <input type="submit" onclick="savePic()">
    </form>

</div>
<script type="text/javascript" src="js/jquery-1.10.2.min.js">
</script>
<script type="text/javascript">
    function uploadPic() {
        var pic = (document.getElementById("pic").files[0]);
        if (pic == null) {
            alert("uploadPic if启动");
        } else {
            var formData = new FormData();
            formData.append("pic", pic);
            var url;
            //debugger
            $.ajax({
                url: "http://47.111.69.237:8092/uploadPic/",
                type: "POST",
                data: formData,
                dataType: "json",
                cache: false,
                processData: false,
                contentType: false,
                async: false,
                success: function (res1) {
                    // alert(res1.data);
                    alert("恭喜，上传成功！");
                    $("#hiddenUrl").attr('value', res1.data);
                },
            })
        }
    }

    function savePic() {
        var picData = document.getElementById("hiddenUrl").value;
        if (picData == null) {
        } else {
            var url = document.getElementById("hiddenUrl").value;
            $.ajax({
                url: "http://47.111.69.237:8092/enterprice/updateLogo/",
                type: "POST",
                data: {"url": url, "id": 1},
                dataType: "json",
                async: false,
                success: function (result) {
                    alert("恭喜，提交成功！");
                    $(location).attr('href', 'out.html');
                }
            })
        }
    }
</script>
</body>
</html>